package org.jsola.hr.constant.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.QdWebSiteSocTypeIndex;

/**
 *【青岛社保险种类型对应编号】excel导入导出时字段值转换
 * @author lyh
 */
public class QdWebSiteSocTypeIndexConverter implements Converter<String> {

    @Override
    public Class<String> supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        QdWebSiteSocTypeIndex qdWebSiteSocTypeIndex = QdWebSiteSocTypeIndex.findByDesc(cellData.getStringValue());
        if (qdWebSiteSocTypeIndex == null) {
            return SafeKit.getString(cellData.getStringValue());
        }
        return qdWebSiteSocTypeIndex.getValue();
    }

    @Override
    public CellData<String> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        QdWebSiteSocTypeIndex qdWebSiteSocTypeIndex = QdWebSiteSocTypeIndex.find(value);
        if (qdWebSiteSocTypeIndex == null) {
            return new CellData<>(value);
        }
        return new CellData<>(qdWebSiteSocTypeIndex.getDesc());
    }
}
